from typing import Annotated

from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session


import models
from auth import get_current_active_user, get_current_active_user, UserPublic
from db import get_db
from models import User

router = APIRouter(prefix="/api/user", tags=["用户"])

@router.get("/all")
def get_user_all(current_user: Annotated[models.User, Depends(get_current_active_user)],db: Session = Depends(get_db)):
    return db.query(User).all()

@router.get("/{user_id}")
def get_user(current_user: Annotated[models.User, Depends(get_current_active_user)],user_id: int, db: Session = Depends(get_db)):
  user = db.query(User).filter(User.id == user_id).first()
  if user is None:
    raise HTTPException(status_code=404, detail="User not found")
  return user

@router.get("/users/me")
def get_current_user(current_user: UserPublic = Depends(get_current_active_user), db: Session = Depends(get_db)):
    return current_user